1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 namespace WarehouseManagementSystem
11 {
12 public partial class frmLoginDetails : Form
13 {
14 ConnectionString cs = new ConnectionString();
15 public frmLoginDetails()
16 {
17 InitializeComponent();
18 }
19
20 private SqlConnection Connection
21 {
22 get
23 {
24 SqlConnection ConnectionToFetch = new SqlConnection(cs.DBConn);
25 ConnectionToFetch.Open();
26 return ConnectionToFetch;
27 }
28 }
29 public DataView GetData()
30 {
31 dynamic SelectQry = "SELECT RTRIM(Username) as [User Name],RTRIM(Password) as [Password] FROM Registration ";
32 DataSet SampleSource = new DataSet();
33 DataView TableView = null;
34 try
35 {
36 SqlCommand SampleCommand = new SqlCommand();
37 dynamic SampleDataAdapter = new SqlDataAdapter();
38 SampleCommand.CommandText = SelectQry;
39 SampleCommand.Connection = Connection;
40 SampleDataAdapter.SelectCommand = SampleCommand;
41 SampleDataAdapter.Fill(SampleSource);
42 TableView = SampleSource.Tables[0].DefaultView;
43 }
44 catch (Exception ex)
45 {
46 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
47 }
48 return TableView;
49 }
50 private void frmLoginDetails_Load(object sender, EventArgs e)
51 {
52 dataGridView1.DataSource = GetData();
53 }
54
55 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
56 {
57 string strRowNumber = (e.RowIndex + 1).ToString();
58 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
59 if (dataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
60 {
61 dataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
62 }
63 Brush b = SystemBrushes.ControlText;
64 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
65 }
66
67
68
69 }
70 }